package com.cskaoyan.controller.backStage;

import com.cskaoyan.exception.MobileValidationException;
import com.cskaoyan.exception.QQValidationException;
import com.cskaoyan.model.vo.*;
import com.cskaoyan.service.ConfigService;
import com.cskaoyan.util.ValidationUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @description：配置管理模块
 * @author     ：huzhouming
 * @date       ：2022/5/6 15:22
 */
@RestController
@RequestMapping("admin/config")
public class ConfigController {
    @Autowired
    ConfigService configService;
    @RequiresPermissions("admin:config:mall")
    @GetMapping("mall")
    /**
     * @author: huzhouming
     * @description: 获取商场配置信息
     * @date: 2022/5/6
     * @param
     * @return com.cskaoyan.model.vo.BaseRespVO
     */
    public BaseRespVO mall(){
        MarketSystemVO marketSystemVO = configService.queryMall();
        return BaseRespVO.ok(marketSystemVO);
    }
    @RequiresPermissions("admin:config:mall")
    @PostMapping("mall")
    /**
     * @author: huzhouming
     * @description: 修改商场配置信息
     * @date: 2022/5/6
     * @param marketSystemVO
     * @return com.cskaoyan.model.vo.BaseRespVO
     */
    public BaseRespVO updateMall(@RequestBody@Validated MarketSystemVO marketSystemVO, BindingResult bindingResult) throws MobileValidationException, QQValidationException {
        ValidationUtil.validMall(bindingResult);
        configService.updateMall(marketSystemVO);
         return BaseRespVO.ok(null);
    }
    @RequiresPermissions("admin:config:express")
    @GetMapping("express")
    /**
     * @author: huzhouming
     * @description: 获取express信息
     * @date: 2022/5/6
     * @param
     * @return com.cskaoyan.model.vo.BaseRespVO
     */
    public BaseRespVO express(){
        ExpressVO expressVO = configService.queryExpress();
        return BaseRespVO.ok(expressVO);
    }
    @RequiresPermissions("admin:config:express")
    @PostMapping("express")
    /**
     * @author: huzhouming
     * @description: 修改Express信息
     * @date: 2022/5/6
     * @param expressVO
     * @return com.cskaoyan.model.vo.BaseRespVO
     */
    public BaseRespVO updateExpress(@RequestBody@Validated ExpressVO expressVO,BindingResult bindingResult) throws MobileValidationException {
        ValidationUtil.validExpress(bindingResult);
        configService.updateExpress(expressVO);
        return BaseRespVO.ok(null);
    }

    @RequiresPermissions("admin:config:order")
    @GetMapping("order")
    /**
     * @author: huzhouming
     * @description: 获取订单配置信息
     * @date: 2022/5/6
     * @param
     * @return com.cskaoyan.model.vo.BaseRespVO
     */
    public BaseRespVO order(){
        ConfigOrderVO configOrderVO = configService.queryOrder();
        return BaseRespVO.ok(configOrderVO);
    }

    @RequiresPermissions("admin:config:order")
    @PostMapping("order")
    /**
     * @author: huzhouming
     * @description: 修改订单配置信息
     * @date: 2022/5/6
     * @param configOrderVO
     * @return com.cskaoyan.model.vo.BaseRespVO
     */
    public BaseRespVO updateOrder(@RequestBody@Validated ConfigOrderVO configOrderVO,BindingResult bindingResult) throws MobileValidationException {
        ValidationUtil.validOrder(bindingResult);
        configService.updateOrder(configOrderVO);
        return BaseRespVO.ok(null);
    }

    @RequiresPermissions("admin:config:wx")
    @GetMapping("wx")
    /**
     * @author: huzhouming
     * @description: 获取小程序配置信息
     * @date: 2022/5/6
     * @param
     * @return com.cskaoyan.model.vo.BaseRespVO
     */
    public BaseRespVO wx(){
        ConfigWxVO configWxVO = configService.queryWx();
        return BaseRespVO.ok(configWxVO);
    }
    @RequiresPermissions("admin:config:wx")
    @PostMapping("wx")
    /**
     * @author: huzhouming
     * @description: 修改小程序订单信息
     * @date: 2022/5/6
     * @param configWxVO
     * @return com.cskaoyan.model.vo.BaseRespVO
     */
    public BaseRespVO updateWx(@RequestBody @Validated ConfigWxVO configWxVO,BindingResult bindingResult) throws MobileValidationException {
        ValidationUtil.validWx(bindingResult);
        configService.updateWx(configWxVO);
        return BaseRespVO.ok(null);
    }
}
